package com.he.quartz.task;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.he.constant.RedisConstant;
import com.he.mapper.VisitLogMapper;
import com.he.service.RedisService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author He
 * @version 1.0
 * @Date 2023/10/20 15:44
 * @Desc
 */
@Component("timedTask")
public class TimedTask {
    @Resource
    private RedisService redisService;

    @Resource
    private VisitLogMapper visitLogMapper;

    /**
     * 清除博客访问记录
     */
    public void clear() {
        redisService.deleteObject(RedisConstant.UNIQUE_VISITOR);
    }

    /**
     * 测试任务
     */
    public void test() {
        System.out.println("测试任务");
    }

    public void test2() {
        System.out.println("测试任务2");
    }


    /**
     * 清除一周前的访问日志
     */
    public void clearVisitLog() {
        DateTime endTime = DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), -7));
        visitLogMapper.deleteVisitLog(endTime);
    }
}
